$(document).ready(function () {
    $("#loginData").validate({
        onkeyup: false,
        focusCleanup: false,
        errorElement: "em",
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: "必填"
            },
            password: {
                required: "必填"
            }
        }
    });


    $("#loginBut").click(function () {
        login();
    });
    window.onkeypress = function (event) {
        if (event.keyCode === 13) {
            login();
        }
    }
});

function login() {
    if ($("#loginData").validate().form()) {
        var formData = $("#loginData").serialize();
        layer.msg('加载中', {
            icon: 16
            , shade: 0.01
        });
        $.ajax({
            data: formData,
            url: "/Olala/login",
            type: "post",
            dataType: "json",
            success: function (result) {
                layer.msg(result.msg);
                if (result.code === 21) {
                    location.href = "/Olala/server/index.html";
                }
            }

        });
    }

}